<template>
    <div style="padding: 10px;">
        <el-form :model="formData" ref="queryForm" :rules="Rules"
                 label-width="auto"
                 @submit.native.prevent>
            <template v-if="true">
                <template v-if="action==='readOnly'">
                </template>
                <template v-else>
                    <el-form-item label="所属分类" desc="所属分类" prop="classId">
                        <classSelectOne v-model="formData.classId"
                                        :text.sync="formData.className"
                                        typeInfo="eventhandlers"
                                        placeholder="所属分类"
                                        clearable
                                        :classApi="{
                                     getList:classApi.getList,
                                     getItem:classApi.getItem,
                                 }"
                                        @change="node=>{
                                  formData.classIdPath=node&&node.classIdPath
                                 }"
                                        size="small" style="width:220px;" />
                    </el-form-item>
                </template>
            </template>
          
            <el-form-item label="名称" desc="名称" prop="name">
                <template v-if="true">
                    <template v-if="action=='readOnly'">
                        <div>
                            {{formData.name}}
                        </div>
                    </template>
                    <template v-else>
                        <el-input v-model.trim="formData.name" placeholder="名称" clearable size="small"
                                  style="width:220px;" />
                    </template>
                </template>
            </el-form-item>
            
            <el-form-item label="处理类型" desc="处理类型1内部方法     5外部接口" prop="handleType">
                <template v-if="true">
                    <template v-if="action==='readOnly'">
                        <dicTag v-model="formData.handleType" :code="dicInner.mes_bpm_handle_handleType">
                        
                        </dicTag>
                    </template>
                    <template v-else>
                        <dicSelect v-model="formData.handleType" :code="dicInner.mes_bpm_handle_handleType"
                                   placeholder="处理类型"
                                   clearable size="small"
                                   style="width:220px;"
                        />
                    </template>
                </template>
            
            
            </el-form-item>
            
            <el-form-item label="处理执行方法" desc="处理执行方法" prop="handleValue">
                <template v-if="true">
                    <template v-if="action==='readOnly'">
                        <div>{{formData.handleValue||'暂无'}}</div>
                    </template>
                    <template v-else>
                        <el-input v-model.trim="formData.handleValue" placeholder="处理执行方法" clearable size="small"
                                  style="width:220px;" />
                    </template>
                </template>
            
            
            </el-form-item>
            <el-form-item label="事件参数" desc="事件参数" prop="handleParam">
                <template v-if="true">
                    <template v-if="action==='readOnly'">
                        <div> {{formData.handleParam||'暂无'}}</div>
                    </template>
                    <template v-else>
                        <el-input v-model.trim="formData.handleParam" placeholder="事件参数" clearable size="small"
                                  style="width:220px;" />
                    </template>
                </template>
            
            
            </el-form-item>
        
        </el-form>
    </div>
</template>
<script>  import { getUrlParam } from '@/utils/index';
import { alertWithPaylod } from '@/utils/alertUtil';
import * as  api from '@/apis/mesBpmHandle.api.js';
import { default as FormDialog } from '@codegenarate/mydialogplus';
import { fillData, validatePromise } from '@/utils/index';

const Rules = {
  'id': [{ required: false, message: '主键ID', trigger: 'blur' }],
  'name': [{ required: true, message: '名称', trigger: 'blur' }],
  'code': [{ required: false, message: '标识码', trigger: 'blur' }],
  'handleType': [{ required: true, message: '处理类型1内部方法', trigger: 'blur' }],
  'state': [{ required: false, message: '状态', trigger: 'blur' }],
  'handleValue': [{ required: true, message: '业务状态标识码', trigger: 'blur' }],
  'handleParam': [{ required: false, message: '业务状态标识码', trigger: 'blur' }],
  'handleHead': [{ required: false, message: '业务状态标识码', trigger: 'blur' }],
  'classId': [{ required: false, message: '所属分类', trigger: 'blur' }],
  'classIdPath': [{ required: false, message: '所有分类路径', trigger: 'blur' }],
  'describeInfo': [{ required: false, message: '备注', trigger: 'blur' }],
  'remarks': [{ required: false, message: '备注', trigger: 'blur' }],
  'tenantType': [{ required: false, message: '租户类型', trigger: 'blur' }],
  'tenantId': [{ required: false, message: '租户ID', trigger: 'blur' }],
  'delState': [{ required: false, message: '有效状态[数据字典=del_state]', trigger: 'blur' }],
  'addUser': [{ required: false, message: '添加人', trigger: 'blur' }],
  'addUserId': [{ required: false, message: '添加人ID', trigger: 'blur' }],
  'addTime': [{ required: false, message: '添加时间', trigger: 'blur' }],
  'editUser': [{ required: false, message: '最近更新人', trigger: 'blur' }],
  'editUserId': [{ required: false, message: '最近更新人ID', trigger: 'blur' }],
  'lastEditTime': [{ required: false, message: '最近更新时间', trigger: 'blur' }],
  'serverNumber': [{ required: false, message: '服务器编号ID', trigger: 'blur' }],
};
const dicInner = {
  'mes_bpm_pipiline_handle_handleStage': 'mes_bpm_pipiline_handle_handleStage',
  '___mes_bpm_handle_id': '主键ID',
  'mes_bpm_handle_id': 'mes_bpm_handle_id',
  '___mes_bpm_handle_name': '名称',
  'mes_bpm_handle_name': 'mes_bpm_handle_name',
  '___mes_bpm_handle_code': '标识码',
  'mes_bpm_handle_code': 'mes_bpm_handle_code',
  '___mes_bpm_handle_handleType': '处理类型1内部方法     5外部接口',
  'mes_bpm_handle_handleType': 'mes_bpm_handle_handleType',
  '___mes_bpm_handle_state': '状态 1 待审核 5使用中 10己关闭',
  'mes_bpm_handle_state': 'mes_bpm_handle_state',
  '___mes_bpm_handle_handleValue': '业务状态标识码',
  'mes_bpm_handle_handleValue': 'mes_bpm_handle_handleValue',
  '___mes_bpm_handle_handleParam': '业务状态标识码',
  'mes_bpm_handle_handleParam': 'mes_bpm_handle_handleParam',
  '___mes_bpm_handle_handleHead': '业务状态标识码',
  'mes_bpm_handle_handleHead': 'mes_bpm_handle_handleHead',
  '___mes_bpm_handle_classId': '所属分类',
  'mes_bpm_handle_classId': 'mes_bpm_handle_classId',
  '___mes_bpm_handle_classIdPath': '所有分类路径',
  'mes_bpm_handle_classIdPath': 'mes_bpm_handle_classIdPath',
  '___mes_bpm_handle_describeInfo': '备注',
  'mes_bpm_handle_describeInfo': 'mes_bpm_handle_describeInfo',
  '___mes_bpm_handle_remarks': '备注',
  'mes_bpm_handle_remarks': 'mes_bpm_handle_remarks',
  '___mes_bpm_handle_tenantType': '租户类型 1应用管理者2应用消息者',
  'mes_bpm_handle_tenantType': 'mes_bpm_handle_tenantType',
  '___mes_bpm_handle_tenantId': '租户ID',
  'mes_bpm_handle_tenantId': 'mes_bpm_handle_tenantId',
  '___mes_bpm_handle_delState': '有效状态[数据字典=del_state] 1有效  5删除',
  'mes_bpm_handle_delState': 'mes_bpm_handle_delState',
  '___mes_bpm_handle_addUser': '添加人',
  'mes_bpm_handle_addUser': 'mes_bpm_handle_addUser',
  '___mes_bpm_handle_addUserId': '添加人ID',
  'mes_bpm_handle_addUserId': 'mes_bpm_handle_addUserId',
  '___mes_bpm_handle_addTime': '添加时间',
  'mes_bpm_handle_addTime': 'mes_bpm_handle_addTime',
  '___mes_bpm_handle_editUser': '最近更新人',
  'mes_bpm_handle_editUser': 'mes_bpm_handle_editUser',
  '___mes_bpm_handle_editUserId': '最近更新人ID',
  'mes_bpm_handle_editUserId': 'mes_bpm_handle_editUserId',
  '___mes_bpm_handle_lastEditTime': '最近更新时间',
  'mes_bpm_handle_lastEditTime': 'mes_bpm_handle_lastEditTime',
  '___mes_bpm_handle_serverNumber': '服务器编号ID',
  'mes_bpm_handle_serverNumber': 'mes_bpm_handle_serverNumber',
};
import * as classApi from '@/apis/class.api.js';
import { deepClone } from '@/utils/index';

export default {
  name: 'mesBpmHandleModify',
  data() {
    return {
      action: '',
      api: api,
      classApi,
      Rules,
      dicInner,
      formData: {
        'id': '',
        'name': '',
        'code': '',
        'handleType': '',
        'state': '',
        'handleValue': '',
        'handleParam': '',
        'handleHead': '',
        'classId': '',
        'classIdPath': '',
        'describeInfo': '',
        'remarks': '',
        'tenantType': '',
        'tenantId': '',
        'delState': '',
        'addUser': '',
        'addUserId': '',
        'addTime': '',
        'editUser': '',
        'editUserId': '',
        'lastEditTime': '',
        'serverNumber': '',
        className: '',
      },
      lists: [],
      selectRows: [],
      classId: '',
      classIdPath: '',
      className: '',
      loading: false,
      isFold: false,
      tableRowClassName({ row, rowIndex }) {
        if (row.rowType == 'total') {
          return 'total-row';
        }
        return '';
      },
    };
  },
  components: {
    svgIcon: () => import('@codegenarate/svg-icon'),
    dicSelect: () => import('@/components/dicselect.vue'),
    dicTag: () => import('@/components/DicSelect/dic-tag.vue'),
    classSelectOne: () => import('@/components/classSelectOne/classSelectOne.vue'),
  },
  props: {
    immediate: {
      type: [Boolean],
      default() {
        return false;
      },
    },
    actionProps: {
      type: [String],
      default() {
        return '';
      },
    },
    item: {
      type: [Object],
      default() {
        return {};
      },
    },
  },
  computed: {},
  watch: {},
  mounted() {
    if (this.$props.immediate) {
      fillData(this.formData, this.$props.item);
      this.action = this.$props.actionProps;
    }
  },
  
  methods: {
    /**       *
     *  @params _data. classId,
     @params _data.className,
     @params _data. classIdPath,
     @params _data.action
     *           * @desc 初始化        */
    async initByDialog(_data) {
      var self = this;
      
      var newData = undefined;
      if (_data && _data.id) {
        var result = await api.getItem(_data.id);
        newData = result && result.data;
      }
      fillData(this.formData, Object.assign(_data, newData));
      console.log('初始化数据', this.formData);
      
      
      this.action = `${_data && _data.action || ''}`;
      
      console.log('action  ', this.action);
      
      
    }, async submitByDialog(_data) {
      var isyes = await validatePromise.call(this, 'queryForm');
      if (!isyes) {
        return { success: false, message: '请检查必填项' };
      }
      var func = this.formData.id ? api.update : api.add;
      var result = await func(this.formData);
      alertWithPaylod(result);
      return result;
    },
  },
};</script>
